package com.AJava1710D.bingfabao.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 作者: LCG
 * 日期: 2020/6/24 08:41
 * 描述:
 */
public class TestConditionUtis {

    private Lock lock=new ReentrantLock();

    private Condition conditionA=lock.newCondition();

    private Condition conditionB=lock.newCondition();


    public void wiatA(){
          lock.lock();
          try{
              System.out.println("=========A=wait");
              conditionA.await();
          }catch (Exception e){

          }finally {
              lock.unlock();
          }

    }


    public void singalA(){
        lock.lock();
        try{
            System.out.println("=========A=singalA");
            conditionA.signal();
        }catch (Exception e){

        }finally {
            lock.unlock();
        }

    }



    public void wiatB(){
        lock.lock();
        try{
            System.out.println("=========B=wait");
            conditionB.await();
        }catch (Exception e){

        }finally {
            lock.unlock();
        }

    }


    public void singalB(){
        lock.lock();
        try{
            System.out.println("=========A=singalB");
            conditionB.signal();
        }catch (Exception e){

        }finally {
            lock.unlock();
        }

    }


}
